package com.itheima.controller;

import com.itheima.domain.PageResult;
import com.itheima.domain.Result;
import com.itheima.domain.StudentQueryParam;
import com.itheima.domain.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 学员列表查询
     */
    @GetMapping
    public Result pageStudents(StudentQueryParam query){
        PageResult<Student> list=studentService.pageStudents(query);
        return Result.success(list);
    }

    /**
     * 根据学员id进行批量删除
     */
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        studentService.delectByIds(ids);
        return Result.success();
    }

    /**
     * 添加学员
     */
    @PostMapping
    public Result insertStudent(@RequestBody Student student){
        studentService.insertStudent(student);
        return Result.success();
    }

    /**
     * 根据id查询员工信息
     * 回显
     */

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Student student=studentService.getById(id);
        return Result.success(student);
    }

    /**
     * 根据id更改学员信息
     */
    @PutMapping
    public Result updateById(@RequestBody Student  student){
        studentService.updateById(student);
        return Result.success();
    }


    /**
     * 违纪处理
     */
    @PutMapping("/violation/{id}/{score}")
    public Result UpdateViolationScore(@PathVariable Integer id,
                                       @PathVariable Integer score){
        studentService.UpdateViolationScore(id,score);
        return Result.success();
    }
}
